package ronin.ai;
import java.util.LinkedList;
import ronin.graphics.Vector2D;

public class Path {
	private LinkedList<Vector2D> breadcrumbs;
	private int MAX = 10;
	private int currentIndex;
	private boolean isClosed;
	private boolean isFinished;
	
	public Path(){
		breadcrumbs = new LinkedList<Vector2D>();
		currentIndex = 0;
		isClosed = false;
		isFinished = false;
	}
	
	public boolean addWaypoint(Vector2D theTargetPosition){
		
		if(breadcrumbs.size() >= MAX) return false;
		
		breadcrumbs.addLast(theTargetPosition);
		
		return true;
	}
	
	public boolean closed(){
		return this.isClosed;
	}
	
	public void setClosed(boolean yesOrNo){
		isClosed = yesOrNo;
	}
	
	public boolean finished(){
		return this.isFinished;
	}
	
	public void purge(){
		breadcrumbs.clear();
	}
	
	public void setNextWaypoint()
	{
		currentIndex++;
		
		if(currentIndex >= MAX)
		{
			if(isClosed) 
			{
				currentIndex = 0;
			}
			else
			{
				currentIndex = MAX;
				isFinished = true;
			}
		}
	}
	
	public Vector2D currentWaypoint(){
		return breadcrumbs.get(currentIndex);
	}
}
